package com.hung.pro.iFlashCards;

import com.hung.pro.iFlashCards.ui.Resources;
import com.hung.pro.iFlashCards.ui.UIHelper;
import com.jgoodies.forms.layout.CellConstraints;
import com.jgoodies.forms.layout.FormLayout;

import javax.swing.*;
import java.awt.event.*;

public class AboutBox extends JDialog {
    private JPanel contentPane;
    private JButton buttonOK;
    private JLabel imageLabel;

    public AboutBox() {
        setContentPane(contentPane);
        setModal(true);
        getRootPane().setDefaultButton(buttonOK);

        buttonOK.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                onOK();
            }
        });

// call onCancel() when cross is clicked
        setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                onCancel();
            }
        });

// call onCancel() on ESCAPE
        contentPane.registerKeyboardAction(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                onCancel();
            }
        }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    }

    private void onOK() {
// add your code here
        dispose();
    }

    private void onCancel() {
// add your code here if necessary
        dispose();
    }

    public void showWindow() {
        this.setModal(true);
        this.setTitle(Resources.getString("window.title.about"));
        //set icon

        ((java.awt.Frame) this.getOwner()).setIconImage(UIHelper.readImageIcon("app.png").getImage());
        this.pack();
        this.setLocationRelativeTo(null);
        this.setVisible(true);
    }

    {
        setupUI();
    }

    /**
     * Create UI
     */
    private void setupUI() {
        contentPane = new JPanel();
        contentPane.setLayout(new FormLayout("fill:max(d;4px):noGrow,left:4dlu:noGrow,fill:d:grow,left:4dlu:noGrow,fill:max(d;4px):noGrow", "center:max(d;4px):grow,top:4dlu:noGrow,center:d:noGrow,top:4dlu:noGrow,center:max(d;4px):noGrow,top:4dlu:noGrow,center:d:noGrow,top:4dlu:noGrow,center:max(d;4px):noGrow"));
        final JPanel panel1 = new JPanel();
        panel1.setLayout(new FormLayout("fill:d:grow,left:4dlu:noGrow,fill:max(d;4px):noGrow", "center:d:grow"));
        CellConstraints cc = new CellConstraints();
        contentPane.add(panel1, cc.xy(3, 9));
        final JPanel panel2 = new JPanel();
        panel2.setLayout(new FormLayout("fill:d:grow", "center:d:grow"));
        panel1.add(panel2, cc.xy(3, 1));
        buttonOK = new JButton();
        buttonOK.setText("OK");
        panel2.add(buttonOK, cc.xy(1, 1));
        final JPanel panel3 = new JPanel();
        panel3.setLayout(new FormLayout("fill:d:grow", "center:d:grow"));
        contentPane.add(panel3, cc.xy(3, 3));
        final JSeparator separator1 = new JSeparator();
        contentPane.add(separator1, cc.xy(3, 7, CellConstraints.FILL, CellConstraints.BOTTOM));
        final JLabel label1 = new JLabel();
        label1.setText("iFlashCards - The product of infoSX. Created by TheBig.                             ");
        contentPane.add(label1, cc.xy(3, 5));
        imageLabel = new JLabel();
        imageLabel.setIcon(new ImageIcon(getClass().getResource("/com/hung/pro/iFlashCards/ui/resources/images/about.png")));
        imageLabel.setText("");
        contentPane.add(imageLabel, cc.xy(3, 1, CellConstraints.CENTER, CellConstraints.DEFAULT));
    }

    /**
     * @noinspection ALL
     */
    public JComponent $$$getRootComponent$$$() {
        return contentPane;
    }
}
